package com.example.controller;


import com.example.entity.Family;
import com.example.entity.Result;
import com.example.service.IFamilyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-17
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/family")
@CrossOrigin
public class FamilyController {

    private final IFamilyService iFamilyService;

    @GetMapping("/select")
    public Result<List<Family>> sel(){
        List<Family> list = iFamilyService.list();
        return Result.success(list);
    }

    @DeleteMapping("/delete")
    public Result del(@RequestParam List<Long> ids){
        log.info("接收到ids为:{}",ids);
        iFamilyService.removeByIds(ids);
        return Result.success();
    }

    @PutMapping("/update")
    public Result upd(@RequestBody Family family){
        iFamilyService.updateById(family);
        return Result.success();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Family family){
        iFamilyService.save(family);
        return Result.success();
    }
}








